package com.weareint.common.utils;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;

@Slf4j
public abstract class DateUtil {

    private static final String FORMAT = "yyyy-MM-dd HH:mm:ss";

    public static Date parse(String dateStr){
        if (null == dateStr){
            return null;
        }
        return DateTime.of(dateStr, FORMAT).toJdkDate();
    }

    public static String format(Date date){
        if (null == date){
            return null;
        }
        return DateTime.of(date).toString(FORMAT);
    }

    /**
     * <pre>
     *      在 date 的基础上减去 count 个月
     * </pre>
     * @param date date
     * @param count cnt
     * @return date
     */
    public static Date minus(Date date, int count){
        return DateTime.of(date).offset(DateField.MONTH, count * -1).toJdkDate();
    }

}
